'use strict';

const { Controller } = require('egg');

class Shop extends Controller {
  async getData() {
    const { service } = this.ctx;
    const data = await service.shop.getData();
    this.ctx.body = {
      code: 'SUCCESS',
      status: 200,
      data,
    };
  }
  async delete() {
    const userInfo = this.ctx.userInfo;
    // console.log(userInfo.type, this.ctx.request.query.id);
    const data = await this.app.mysql.query(`select * from rules where rulename='${userInfo.type}'`);
    if (data[0].apis.includes('/removeShop')) { // 有当前权限
      await this.app.mysql.delete('shop', { id: this.ctx.request.query.id });
      this.ctx.body = {
        code: 'SUCCESS',
        msg: '删除成功',
      };
    } else {
      this.ctx.status = 403;
      this.ctx.body = {
        code: 'FAIL',
        msg: '您暂无删除权限',
      };
    }
  }
}

module.exports = Shop;
